import tkinter as tk
import random
def click():
    #初始化清空
    txt1.delete(0,tk.END)
    txt2.delete(0,tk.END)
    #产生随机数100-1000内的奇数
    n = random.randint(100,499)*2+1
    flag = 1
    i = 3
    while i<=n-1:
        if(n%i == 0):
            flag = 0
            break
        i = i + 2
    txt1.insert(0, n);
    if(flag):
        txt2.insert(0, str(n) + "是素数")
    else:
        txt2.insert(0, str(n) + "不是素数")
                
win=tk.Tk()
win.title('素数判断')
win.geometry ('400x200')
win.resizable(0,0)

btn = tk.Button(win,text='产生奇数并判断',command=click)
lb1 = tk.Label(win,text='随机产生的三位正奇数：')
lb2 = tk.Label(win,text='判断结果：')
txt1 = tk.Entry(win)
txt2 = tk.Entry(win)

txt1.grid(row=2,column=2)
txt2.grid(row=4,column=2)
lb1.grid(row=2,column=1)
lb2.grid(row=4,column=1)
btn.grid(row=1,column=1,columnspan=2,pady=10)

win.mainloop()
          
